package com.compass.doctor.ui.prescription

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.compass.doctor.databinding.ActivityPrescriptionTemplateBinding
import com.compass.doctor.ui.prescription.fragment.HistoryPrescriptionFragment
import com.compass.doctor.ui.prescription.fragment.HistoryTemplateFragment
import com.compass.framework.adapter.ViewPage2FragmentAdapter
import com.compass.doctor.base.BaseVBActivity
import com.compass.framework.constant.CHAT_INFO

/**
 * Description： 处方模板
 * Date:2023/12/19 10:15
 */
class PrescriptionTemplateActivity : BaseVBActivity<ActivityPrescriptionTemplateBinding>(){


    companion object {
        fun start(context: Context, userInfo: Int) {
            val intent = Intent(context, PrescriptionTemplateActivity::class.java)
            intent.putExtra(CHAT_INFO, userInfo)
            context.startActivity(intent)
        }
    }

    private lateinit var viewPageAdapter: ViewPage2FragmentAdapter
    private var fragments: ArrayList<Fragment> = ArrayList()

    private lateinit var historyTemplateFragment: HistoryTemplateFragment
    private lateinit var historyPrescriptionFragment: HistoryPrescriptionFragment


    override fun initView(savedInstanceState: Bundle?) {
        initFragment()
        mBinding.dslTab.tabIndicator.indicatorWidth = -2
        mBinding.dslTab.tabIndicator.indicatorEnableFlow = true
        mBinding.dslTab.configTabLayoutConfig {
            onSelectIndexChange = { _, selectIndexList, _, _ ->
                val toIndex = selectIndexList.first()
                mBinding.viewpager2.setCurrentItem(toIndex, false)
            }
        }
        viewPageAdapter = ViewPage2FragmentAdapter(supportFragmentManager, lifecycle, fragments)
        mBinding.viewpager2.adapter = viewPageAdapter
        mBinding.viewpager2.isUserInputEnabled = false//禁止viewPage滑动
        mBinding.viewpager2.setCurrentItem(0, false)

    }

    private fun initFragment() {
        historyTemplateFragment = HistoryTemplateFragment()
        fragments.add(historyTemplateFragment)

        historyPrescriptionFragment = HistoryPrescriptionFragment()
        fragments.add(historyPrescriptionFragment)

    }


}